var HOST = $('body').attr('data-host');
$(function () {
    $('input').keydown(function () {
        $('#insert_info').removeAttr('disabled');
    });

    $('#insert_info').click(function () {
        if(!$('input[name=item]').val()){
            alert('功能名称不能为空哦');
            return false;
        }
        $('#insert_info').attr('disabled','disabled');
        $.ajax({
            type: 'POST',
            url: HOST + "/Cloud.feature/addfeature",
            data: $('.form-horizontal').serialize(),// 你的formid
            async: false,
            success:function (data) {
                if(data.info == 1){
                    toastr.success('新增成功')
                }else {
                    toastr.success('发生异常');
                }
            }

        });
        location.reload();
    });


    $('input').keydown(function () {
        $('#save').removeAttr('disabled');
    });

    $("button[name=save]").click(function () {
        var id = $(this).attr("id");
        var item = $("#ceshi"+id).val();

        $.ajax({
            type:'POST',
            url: HOST + "/cloud.feature/savefeature",
            data : {'id': id,'item':item},
            async:false,
            success:function (data) {
                if(data.info == 1){
                    toastr.success('保存成功');
                }else{
                    toastr.error('发生异常');
                }
            }
        });
        $('.modal').modal('hide');
        $("#td"+id).text(item);

    });




    $("a[name='del']").click(function () {
        if(confirm("您是否确定要删除")){
            $.ajax({
                type: 'POST',
                url: HOST + '/cloud.feature/delfeature',
                data : {'id':$(this).attr("value")},
                async : false,
                success : function (data) {
                    if(data.info == 1){

                        toastr.success('删除成功');
                    }else{
                        toastr.error('发生异常');
                    }
                }
            });
            $(this).parents('tr').remove();
        }
    })



});
